package cn.hdu.liang.ch2;


class B {
    public void printClassName(EscapeAnalysisClass g) {
        System.out.println(g.getClass().getName());
    }
}

//代码清单2-7 逃逸分析示例代码 escapeAnalysisClass
public class EscapeAnalysisClass {
    public static B b;

    public void globalVariablePointerEscape() { //给全局变量赋值，发生逃逸
        b = new B();
    }

    public B methodPointerEscape() { //方法返回值，发生逃逸
        return new B();
    }

    public void instancePassPointerEscape() {
        methodPointerEscape().printClassName(this);//实例引用发生逃逸
    }
}